* {
    box-sizing: border-box;
}

body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    margin: 0;
}

/* 选项容器 */
.toggle-container {
    display: flex;
    align-items: center;
    margin: 10px 0;
    width: 200px;
}

/* 输入框 */
.toggle {
    visibility: hidden;
}

/* 按钮 */
.label {
    position: relative;
    display: inline-block;
    margin: 0 15px 0;
    width: 80px;
    height: 40px;
    border-radius: 20px;
    background-color: #d0d0d0;
    cursor: pointer;
}

/* 点击,label背景变色 */
/* 原理:利用label与input绑定,点击label等于点击input */
.toggle:checked+.label {
    background-color: darkgreen;
}

/* label按钮中的圆球 */
/* 关键点:点击球滚动 */
.ball {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background-color: #fff;
    animation: slideOff .3s linear forwards;
}

/* 选中时,球的运动轨迹 */
.toggle:checked+.label .ball {
    animation: slideOn .3s linear forwards;
}

/* 关键点:球运动的轨迹 */
@keyframes slideOn {
    from {
        transform: translateX(0) scale(1);
    }

    50% {
        transform: translateX(20px) scale(1.2);
    }

    to {
        transform: translateX(40px) scale(1);
    }
}

@keyframes slideOff {
    from {
        transform: translateX(40px) scale(1);
    }

    50% {
        transform: translateX(20px) scale(1.2);
    }

    to {
        transform: translateX(0) scale(1);
    }
}